package com.sunshine.wrongquestionset.activity.subject_analyzer

import android.app.Application
import androidx.lifecycle.AndroidViewModel
import androidx.lifecycle.LiveData
import com.sunshine.wrongquestionset.room.entity.*
import com.sunshine.wrongquestionset.room.repository.MyRepository
import java.util.*

/**
 * @author sunshine
 * @date 2021/4/17
 */
class SubjectAnalyzerViewModel(application: Application) : AndroidViewModel(application) {
    private val repository: MyRepository = MyRepository(application.applicationContext)

    fun getWrongQuestionBySubjectId(subjectId: Int): LiveData<List<WrongQuestionBean>?> {
        return repository.getWrongQuestionBeanInSubjectIdAndInDate(subjectId, 0, Date().time)
    }

    fun getAllQuestionType(): LiveData<List<QuestionTypeEntity>?> {
        return repository.getAllQuestionType()
    }

    fun getQuestionBySubjectId(subjectId: Int): LiveData<List<QuestionEntity>?> {
        return repository.getQuestionBySubject(subjectId)
    }

    fun getTodayWrongQuestion(): LiveData<List<WrongQuestionBean>?> {
        val today = Date()
        return repository.getWrongQuestionBeanInDate(today.time - com.sunshine.wrongquestionset.utils.TimeUtils.DAY_LONG, today.time)
    }

    fun getAllQuestionInfo(): LiveData<List<QuestionInfoEntity>?> {
        return repository.getAllQuestionInfo()
    }

}